local ma__jielian = fk.CreateSkill {
  name = "ma__jielian",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["ma__jielian"] = "劫炼",
  [":ma__jielian"] = "锁定技，当你受到属性伤害时，你回满体力；当你不因属性伤害进入濒死状态时，你进行一次【浮雷】判定并获得判定牌。",

  ["$ma__jielian1"] = "",
  ["$ma__jielian2"] = "",
}

ma__jielian:addEffect(fk.DamageInflicted, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(ma__jielian.name) and target == player and
      player:isWounded() and data.damageType ~= fk.NormalDamage
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
      room:recover{
      who = player,
      num = player:getLostHp(),
      recoverBy = player,
      skillName = ma__jielian.name,
    }
  end,
})

ma__jielian:addEffect(fk.EnterDying, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    return target == player and player:hasSkill(ma__jielian.name) and
      not (data.damage and data.damage.damageType ~= fk.NormalDamage)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local x = 1
    local room = player.room
      local judge = {
        who = player,
        reason = "floating_thunder",
        pattern = ".|.|spade",
      }
      player.room:addPlayerMark(player, "ma__jielian")
      room:judge(judge)
      if judge:matchPattern() then
        room:damage{
          to = player,
          damage = x,
          damageType = fk.ThunderDamage,
          skillName = "floating_thunder_skill",
        }
        x = x + 1
      end
  end,
})

ma__jielian:addEffect(fk.FinishJudge, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and data.reason == "floating_thunder" and player:getMark("ma__jielian") > 0 and
    player:isAlive() and player.room:getCardArea(data.card.id) == Card.Processing
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "ma__jielian", 0)
    player.room:obtainCard(player.id, data.card, true)
  end,
})

return ma__jielian